package com.example.demo.domain.entity;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 订单明细
 *
 * @author ouchengchang
 */
@NoArgsConstructor
@Data
public class OrderDetail {

    /**
     * 商品名称
     */
    private String name;

    /**
     * 商品单价（原价）
     */
    private Double amount;

    /**
     * 优惠占比
     */
    private Double rate;

    /**
     * 优惠金额
     */
    private Double discount;

    /**
     * 实付金额
     */
    private Double pay;

    public OrderDetail(String name, Double amount) {
        this.name = name;
        this.amount = amount;
    }

    /**
     * 计算实付金额
     *
     * @param totalOrderAmount    主订单总金额
     * @param totalDiscountAmount 主订单总优惠金额
     */
    public void calcPayAmount(Double totalOrderAmount, Double totalDiscountAmount) {
        this.rate = this.amount / totalOrderAmount;
        this.discount = totalDiscountAmount * this.rate;
        this.pay = this.amount - this.discount;
    }

}
